package com.lagou.boot;

import com.lagou.client.CuratorClient;
import org.apache.curator.RetryPolicy;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.ExponentialBackoffRetry;
import org.apache.zookeeper.CreateMode;

public class Create_Session_Sample {
    public static void main(String[] args) throws Exception {
        RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3);

        CuratorFramework client = CuratorFrameworkFactory.builder()
                .connectString("192.168.228.130:2181") //server地址
                .sessionTimeoutMs(50000) // 会话超时时间
                .connectionTimeoutMs(30000) // 连接超时时间
                .retryPolicy(retryPolicy) // 重试策略
                .namespace("base") // ⽴命名空间/base
                .build(); //
        client.start();
        System.out.println("Zookeeper session2 established. ");
        //添加节点
        String path = "/lg-curator/c1";
        client.create().creatingParentsIfNeeded().withMode(CreateMode.PERSISTENT).forPath(path,"init".getBytes());
//      client.create().creatingParentContainersIfNeeded().withMode(CreateMode.EPHEMERAL).forPath(CuratorClient.path + "/8999" , String.valueOf(System.currentTimeMillis()).getBytes());

        System.out.println("success create znode"+path);
    }
}